package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.UserEmployerInfo;
import cn.anxingongyou.anxin.mapper.UserEmployerInfoMapper;
import cn.anxingongyou.anxin.service.UserEmployerInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class UserEmployerInfoServiceImpl implements UserEmployerInfoService {

    private final UserEmployerInfoMapper userEmployerInfoMapper;
    @Autowired
    public UserEmployerInfoServiceImpl(UserEmployerInfoMapper userEmployerInfoMapper) {
        this.userEmployerInfoMapper = userEmployerInfoMapper;
    }

    @Override
    public int insert(UserEmployerInfo userEmployerInfo) {
        return userEmployerInfoMapper.insertSelective(userEmployerInfo);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return userEmployerInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(UserEmployerInfo userEmployerInfo) {
        return userEmployerInfoMapper.updateByPrimaryKeySelective(userEmployerInfo);
    }

    @Override
    public UserEmployerInfo selectOne(UserEmployerInfo userEmployerInfo) {
        return userEmployerInfoMapper.selectOne(userEmployerInfo);
    }

    @Override
    public UserEmployerInfo selectOneByPrimaryKey(Long id) {
        return userEmployerInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<UserEmployerInfo> page(int pageNum, int pageSize, UserEmployerInfo userEmployerInfo) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<UserEmployerInfo> list = userEmployerInfoMapper.select(userEmployerInfo);
        PageInfo<UserEmployerInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<UserEmployerInfo> search(int pageNum, int pageSize, UserEmployerInfo userEmployerInfo) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);

        Example example = new Example(UserEmployerInfo.class);
        Example.Criteria criteria = example.createCriteria();
        if(userEmployerInfo.getId() != null){
            criteria.andEqualTo("id",userEmployerInfo.getId());
        }
        if(userEmployerInfo.getEnterpriseName() != null){
            criteria.andLike("enterpriseName", "%" +userEmployerInfo.getEnterpriseName()+ "%");
        }
        if(userEmployerInfo.getNature() != null){
            criteria.andLike("nature","%" +userEmployerInfo.getNature()+ "%");
        }
        if(userEmployerInfo.getIndustry() != null){
            criteria.andLike("industry","%" +userEmployerInfo.getIndustry()+ "%");
        }
        if(userEmployerInfo.getScale() != null){
            criteria.andLike("scale","%" +userEmployerInfo.getScale()+ "%");
        }
        if(userEmployerInfo.getPhone() != null){
            criteria.andEqualTo("phone", userEmployerInfo.getPhone());
        }
        if(userEmployerInfo.getIsAuth() != null){
            criteria.andEqualTo("isAuth", userEmployerInfo.getIsAuth());
        }
        if(userEmployerInfo.getIsVip() != null){
            criteria.andEqualTo("isVip", userEmployerInfo.getIsVip());
        }
        List<UserEmployerInfo> list = userEmployerInfoMapper.selectByExample(example);
        PageInfo<UserEmployerInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
